package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsRegionMapper;
import com.qf.pojo.DtsRegion;
import com.qf.service.RegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class RegionServiceImpl implements RegionService {

    @Autowired
    private DtsRegionMapper regionMapper;

    @Override
    public IPage<DtsRegion> findByPage(Integer page, Integer limit, String name, String code) {
        Page<DtsRegion> pageParam = new Page<>(page, limit);
        QueryWrapper<DtsRegion> queryWrapper= new QueryWrapper<>();
        if (!StringUtils.isEmpty(name)){
            queryWrapper.like("name", name);
        }
        if (!StringUtils.isEmpty(code)){
            queryWrapper.like("code", code);
        }
        Page<DtsRegion> pageResult = regionMapper.selectPage(pageParam, queryWrapper);
        return pageResult;
    }
}
